<?php

namespace App\Providers;

use App\User;
use EasyWeChat\Factory;
use Encore\Admin\Auth\Database\Administrator;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        if (config('app.env')=='local'){
            \Auth::guard('api')->login(User::find(9));
            \Auth::guard('admin')->login(Administrator::find(	1));
            \DB::listen(function($query) {
                $bindings = $query->bindings;
                $sql = $query->sql;
                foreach ($bindings as $replace){
                    $value = is_numeric($replace) ? $replace : "'".$replace."'";
                    $sql = preg_replace('/\?/', $value, $sql, 1);
                }
                Log::info($sql);
            });
        }
        \Schema::defaultStringLength(191);
        \Validator::extend('mobile', function ($attribute, $value, $parameters, $validator) {
            return preg_match('/^13\d{9}$|^14\d{9}$|^15\d{9}$|^19\d{9}$|^17\d{9}$|^18\d{9}$/', $value);
        });
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

    }
}
